package com.qixin.modules.thread;

import com.qixin.activiti.service.*;
import com.qixin.modules.log.entity.SysInterfaceLog;
import com.qixin.modules.log.service.ISysInterfaceLogService;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.activiti.entity.ActBusiness;

/**
 * @Description: TODO
 * @author: CYS
 * @date: 2022年04月01日 20:03
 */
public class ActivitiThread extends Thread{

    private IEaLoanbillBXNCItfService iEaLoanbillBXNCItfService;
    private IEaCommunicationsBXNCItfService iEaCommunicationsBXNCItfService;
    private IEaEntertainBXNCItfService iEaEntertainBXNCItfService;
    private IEaPaymentBXNCItfService iEaPaymentBXNCItfService;
    private IEaRepaymentbillBXNCItfService iEaRepaymentbillBXNCItfService;
    private IEaTravelBXNCItfService iEaTravelBXNCItfService;
    private ISysInterfaceLogService logServiceImpl;
    private ActBusiness actBusiness;
    private String billNo;
    private String eventName;
    private String tag;

    public ActivitiThread(ActBusiness actBusiness, String billNo, String eventName, String tag){
        this.actBusiness=actBusiness;
        this.billNo=billNo;
        this.eventName=eventName;
        this.tag=tag;
    }

    @Override
    public void run() {


        //获取记录日志service实例
        if (null==logServiceImpl) {
            logServiceImpl = (ISysInterfaceLogService) SpringContextUtils.getBean("sysInterfaceLogServiceImpl");
        }



        try {
            if(tag.equals("eaCommunications")){
                //获取通讯报销service实例
                if(null==iEaCommunicationsBXNCItfService) {
                    iEaCommunicationsBXNCItfService = (IEaCommunicationsBXNCItfService) SpringContextUtils.getBean("eaCommunicationsBXNCItfServiceImpl");
                }
                //日志保存
                SysInterfaceLog sysInterfaceLog = iEaCommunicationsBXNCItfService.bXApprove(actBusiness, billNo);
                sysInterfaceLog.setName("监听器("+eventName+"事件)推送NC通讯费用报销审核通过接口eaCommunications");
                logServiceImpl.saveInterfaceLog(sysInterfaceLog);

            }else if(tag.equals("eaEntertain")){
                //获取招待费报销service实例
                if(null==iEaEntertainBXNCItfService) {
                    iEaEntertainBXNCItfService = (IEaEntertainBXNCItfService) SpringContextUtils.getBean("eaEntertainBXNCItfServiceImpl");
                }
                //日志保存
                SysInterfaceLog sysInterfaceLog = iEaEntertainBXNCItfService.bXApprove(actBusiness, billNo);
                sysInterfaceLog.setName("监听器("+eventName+"事件)推送NC招待费用报销审核通过接口eaEntertain");
                logServiceImpl.saveInterfaceLog(sysInterfaceLog);
            }else if(tag.equals("eaLoanbill")){
                //获取借款单报销service实例
                if(null==iEaLoanbillBXNCItfService) {
                    iEaLoanbillBXNCItfService = (IEaLoanbillBXNCItfService) SpringContextUtils.getBean("eaLoanbillBXNCItfServiceImpl");
                }
                //日志保存
                SysInterfaceLog sysInterfaceLog = iEaLoanbillBXNCItfService.bXApprove(actBusiness, billNo);
                sysInterfaceLog.setName("监听器("+eventName+"事件)推送NC借款单审核通过接口eaLoanbill");
                logServiceImpl.saveInterfaceLog(sysInterfaceLog);

            }else if(tag.equals("eaPayment")){
                //获取自资金审批单报销service实例
                if(null==iEaPaymentBXNCItfService) {
                    iEaPaymentBXNCItfService = (IEaPaymentBXNCItfService) SpringContextUtils.getBean("eaPaymentBXNCItfServiceImpl");
                }
                //日志保存
                SysInterfaceLog sysInterfaceLog = iEaPaymentBXNCItfService.bXApprove(actBusiness, billNo);
                sysInterfaceLog.setName("监听器("+eventName+"事件)推送NC资金审批单审核通过接口eaPayment");
                logServiceImpl.saveInterfaceLog(sysInterfaceLog);

            }else if(tag.equals("eaRepaymentbill")){
                //获取还款单service实例
                if(null==iEaRepaymentbillBXNCItfService) {
                    iEaRepaymentbillBXNCItfService = (IEaRepaymentbillBXNCItfService) SpringContextUtils.getBean("eaRepaymentbillBXNCItfServiceImpl");
                }
                //日志保存
                SysInterfaceLog sysInterfaceLog = iEaRepaymentbillBXNCItfService.bXApprove(actBusiness, billNo);
                sysInterfaceLog.setName("监听器("+eventName+"事件)推送NC还款单审核通过接口eaRepaymentbill");
                logServiceImpl.saveInterfaceLog(sysInterfaceLog);

            }else if(tag.equals("eaTravel")) {
                //获取差旅费报销service实例
                if(null==iEaTravelBXNCItfService) {
                    iEaTravelBXNCItfService = (IEaTravelBXNCItfService) SpringContextUtils.getBean("eaTravelBXNCItfServiceImpl");
                }
                //日志保存
                SysInterfaceLog sysInterfaceLog = iEaTravelBXNCItfService.bXApprove(actBusiness, billNo);
                sysInterfaceLog.setName("监听器("+eventName+"事件)推送NC差旅费用报销审核通过接口eaTravel");
                logServiceImpl.saveInterfaceLog(sysInterfaceLog);
            }


        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
